<template>
  <el-card>
    <div :id="pieId" style="width: 100%; height: 400px" />
  </el-card>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'PicChart',
  props: {
    pieId: {
      type: String,
      default() {
        return 'categorie-pie-chart'
      }
    },
    pieTitle: {
      type: String,
      default() {
        return '文章分类统计'
      }
    },
    pieData: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      myChart: null
    }
  },
  computed: {
    echartsConfig() {
      return {
        title: {
          text: this.pieTitle,
          textStyle: {
            color: '#767676'
          }
        },
        tooltip: {
          trigger: 'item'
        },
        grid: {

        },
        series: [
          {
            roseType: 'radius',
            data: this.pieData,
            type: 'pie',
            smooth: true
          }
        ]
      }
    }
  },
  watch: {
    pieData(oldValue, newValue) {
      this.myChart?.setOption(this.echartsConfig)
    }
  },
  mounted() {
    this.initCharset()
  },
  methods: {
    initCharset() {
      this.$nextTick(() => {
        this.myChart = echarts.init(document.getElementById(this.pieId))
        this.myChart.setOption(this.echartsConfig)
      })
    }
  }
}
</script>

<style scoped>

</style>
